
"use strict";

angular.module('app.project').controller('DeviceBindCtrl', function ($scope, projectHttpS ,$http, $cookieStore,$stateParams) {
    $scope.userid = $cookieStore.get('userid');
    //获得所有项目
    $http.get('api/project.json').then(function(res){
        var arr = [];
        if($cookieStore.get("user_id") == 1){//超级管理员
            arr = res.data;
        }else{
            for(var i=0;i<res.data.length;i++){
                if(res.data[i].fid == $cookieStore.get("user_id")){
                    arr.push(res.data[i]);
                }
            }
        }
        $scope.projects = arr;
    });
    //获得所有设备
    $http.get('api/device.json').then(function(res){
        var arr = [];
        if($cookieStore.get("user_id") == 1){//超级管理员
            arr = res.data;
        }else{
            for(var i=0;i<res.data.length;i++){
                if(res.data[i].fid == $cookieStore.get("user_id")){
                    arr.push(res.data[i]);
                }
            }
        }
        $scope.devices = arr;
    });

    $scope.bindObj = {
        device_id: $("#device-id option:selected").val(),
        pid: null,
    };
    $("#device-id").change(function(){
        // console.log($("#device-id option:selected").val())
        // console.log($scope.bindObj.device_id)//????
        $("#device_table tbody tr").removeClass();
        var tr =  $scope.bindObj.device_id;
        $("#device_table tbody tr:eq("+ tr-- +")").addClass("success");
    })

    $scope.bind_dialog = function(){
        $("#bind").modal("show");
    }
    $scope.bind = function(){
        console.log('将设备'+$scope.bindObj.device_id+'与项目'+$scope.bindObj.pid+'绑定');
        $("#bind").modal("hide");
    }
        
            
});